package diet.controller;

import diet.service.DietRecordVO;
import diet.service.DietService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Date;

/**
 * Created by zyj on 2018/4/12.
 */
@RestController
@RequestMapping(value = "/api/Diet")
public class DietController {

    @Autowired
    private DietService dietService;

    //显示某用户、某一天的饮食记录
    @RequestMapping(value = "/records", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetDietRecord(Integer userId,Date date) {
        return dietService.selcetDietRecord(userId,date);
    }

    //添加饮食记录
    @RequestMapping(value = "/records", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String insertDietRecord(@RequestBody DietRecordVO dietRecordVO){
        System.out.println("controller");
        return dietService.insertDietRecord(dietRecordVO);
    }

    //删除饮食记录
    @RequestMapping(value = "/records", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delectDietRecord(Integer id){
        return dietService.delectDietRecord(id);
    }

    //更新饮食记录
    @RequestMapping(value = "/recordsUpdate", method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateDietRecord(@RequestBody DietRecordVO dietRecordVO){
        System.out.println("controller");
        return dietService.updateDietRecord(dietRecordVO);
    }

    @RequestMapping(value = "/record", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetDietRecordById(Integer dietRecordId){
        System.out.println("controller");
        return dietService.selcetDietRecordById(dietRecordId);
    }

    //显示某id对应的食物信息
    @RequestMapping(value = "/diet", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetDietById(Integer dietId) {
        return dietService.selcetDietById(dietId);
    }

    //显示食物列表
    @RequestMapping(value = "/dietList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String selcetALLDiet() {
        return dietService.selcetALLDiet();
    }

    //搜索食物
    @RequestMapping(value = "/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String searchDietByNmae(String name) {
        System.out.println("in controller");
        return dietService.searchDietByNmae(name);
    }


}